[android]layout like printest

Posted by Dcboy on Stack Overflow See other posts from Stack Overflow or by Dcboy
Published on 2012-03-26T03:54:40Z Indexed on 2012/03/26 5:29 UTC
Read the original article Hit count: 117

Filed under:

I want to make a custom view like pinterest in my code,i use scrollView and 3 linearlayout inside scrollview I custom my view name waterfallView here is the code:

public class WaterfallView extends LinearLayout {

private ListAdapter m_Adapter;
private OnClickListener onClickListener = null;
private LinearLayout m_Line1;
private LinearLayout m_Line2;
private LinearLayout m_Line3;

public WaterfallView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    InitLine();
}

public WaterfallView(Context context, AttributeSet attrs) {
    super(context, attrs);
    InitLine();
}

private void InitLine() {

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    lp.weight = 1;

    // line2
    m_Line1 = new LinearLayout(this.getContext());
    m_Line1.setOrientation(VERTICAL);
    m_Line1.setLayoutParams(lp);

    // line2
    m_Line2 = new LinearLayout(this.getContext());
    m_Line2.setOrientation(VERTICAL);
    m_Line2.setLayoutParams(lp);

    // line3
    m_Line3 = new LinearLayout(this.getContext());
    m_Line3.setOrientation(VERTICAL);
    m_Line3.setLayoutParams(lp);

    addView(m_Line1);
    addView(m_Line2);
    addView(m_Line3);
}

public ListAdapter getAdapter() {
    return m_Adapter;
}

private void BindLayout() {
    int count = m_Adapter.getCount();
    for (int i = 0; i < count; i++) {
        View v = m_Adapter.getView(i, null, null);
        v.setOnClickListener(this.onClickListener);
        if (i == 0 || i % 3 == 0)
            m_Line1.addView(v);

        if (i == 1 || i % 3 == 1)
            m_Line2.addView(v);

        if (i == 2 || i % 3 == 2)
            m_Line3.addView(v);
    }
    Log.v("countTAG", "" + count);
}

private void AddItem(){

}

public void setAdapter(ListAdapter adapter) {
    this.m_Adapter = adapter;
    BindLayout();
}

public OnClickListener getOnclickListner() {
    return onClickListener;
}

public void setOnclickLinstener(OnClickListener onClickListener) {
    this.onClickListener = onClickListener;
    }
}

In the BindLayout function there is m_Adapter.getView(i, null, null); then the second param convertView i would like to have AbsListView class using RecycleBin How could I do that?

© Stack Overflow or respective owner

Related posts about android